#ifndef __CC_CONF_READ_H__
#define __CC_CONF_READ_H__

#include <stdint.h>
#include <libcc_net/eth.h>
#include <libcc_net/ip.h>
#include <libcc_net/udp.h>
#include <libcc_net/tcp.h>
#include <libcc_net/dns.h>


#define DDOS_TYPE_BASE    0xE0000000
#define DDOS_TYPE_ETHNATE 0xf0000000
#define DDOS_TYPE_IP     (DDOS_TYPE_ETHNATE | 0x01000000)
#define DDOS_TYPE_ARP    (DDOS_TYPE_ETHNATE | 0x02000000)

#define DDOS_TYPE_IP_TCP  (DDOS_TYPE_IP | 0x00100000)
#define DDOS_TYPE_IP_UDP  (DDOS_TYPE_IP | 0x00200000)
#define DDOS_TYPE_IP_ICMP (DDOS_TYPE_IP | 0x00300000)

#define DDOS_TYPE_IP_UDP_DNS (DDOS_TYPE_IP_UDP | 0x00010000)

#define DDOS_TYPE_IP_TCP_HTTP  (DDOS_TYPE_IP_TCP | 0x00010000)


struct ddos_type_name
{
    const char* name;
    int type;
};

static struct ddos_type_name ddos_type_names[] = 
{
    {"tcp_flood", DDOS_TYPE_IP_TCP},
    {"udp_flood", DDOS_TYPE_IP_UDP},
    {"http_flood", DDOS_TYPE_IP_TCP_HTTP},
    {"dns_flood", DDOS_TYPE_IP_UDP_DNS},
    {0, 0},
};

static inline int get_type_from_name(const char* name)
{
    int i;
    for(i = 0;; i++)
    {
        if (0 == ddos_type_names[i].name)
        {
            return DDOS_TYPE_BASE;
        }

        if (0 == strcmp(ddos_type_names[i].name, name))
        {
            return ddos_type_names[i].type;
        }
    }

    return DDOS_TYPE_BASE;
}

// #define DDOS_TYPE_PAYLOAD 0xfffffff

struct send_control
{
    uint32_t pps;
    char interface[128];
    int total_count;
    char pcap_file[256];
    // unsigned int sampling_rate;

    uint32_t usleep_count;
};

struct payload_conf
{
    char payload[2048];
    int payload_len;
};

struct ddos_conf
{
    //
    // Type
    //
    int type;  // 0, udp;

    struct send_control control;
    struct payload_conf payload;

    //
    // Ethernate layer setting
    //

    struct ethhdr eth_h;

    //
    // Ip layer setting
    //
    struct iphdr ip_h;
    struct subnet_info source_subnet;
    struct subnet_info dest_subnet;
    int source_netmask;
    int dest_netmask;

    struct udphdr udp_h;
    struct tcphdr tcp_h;

    //
    // Translate layer.
    //
    struct dnshdr dns_h;
    char query_domain[512];
    
    char http_header[2048];
};

extern struct ddos_conf global_ddos_conf;

int parse_configuration_xml(const char* type_name, const char* file);


#endif

